﻿namespace Sidvall.IdentityManager.Data
{
	public sealed class PluginUserCollection : System.Collections.ObjectModel.KeyedCollection<string, PluginUser>
	{
		#region Public Members

		#region Add

		public PluginUser Add(string userId, string data1)
		{
			return Add(userId, data1, null, null);
		}
		public PluginUser Add(string userId, string data1, string data2)
		{
			return Add(userId, data1, data2, null);
		}
		public PluginUser Add(string userId, string data1, string data2, string data3)
		{
			PluginUser item;

			item = new PluginUser()
			{
				UserId = userId,
				Data1 = data1,
				Data2 = data2,
				Data3 = data3,
			};
			Add(item);
			return item;
		}

		#endregion
		#region FindItemById

		public PluginUser FindItemById(string userId)
		{
			if (string.IsNullOrWhiteSpace(userId))
				return null;
			if (!Contains(userId))
				return null;
			return this[userId];
		}

		#endregion
		#region GetKeyForItem

		protected override string GetKeyForItem(PluginUser item)
		{
			if (item == null)
				throw new System.ArgumentNullException("item");
			return item.UserId;
		}

		#endregion

		#endregion
		#region Constructors

		public PluginUserCollection()
			: base(System.StringComparer.OrdinalIgnoreCase)
		{
		}

		#endregion
	}
}
